import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/3/2 15:18
 */

public class Solution {
    public int longestOnes(int[] nums, int k){
        int ret = 0;
        for (int left = 0,right = 0,zero = 0;right < nums.length; right++){
            if(nums[right] == 0) zero++;//进窗口
            while(zero > k){//判断
                if(nums[left++] == 0) zero--;//出窗口
                ret = Math.max(ret,right-left+1);
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int size = in.nextInt();
            int[] nums = new int[size];
            for (int i = 0; i < size; i++) {
                nums[i] = in.nextInt();
            }
            int k = in.nextInt();
            Solution solution = new Solution();
            System.out.println(solution.longestOnes(nums, k));
        }
    }
}
